{$MODE objfpc}

unit PythonIntObject;

// Integer object interface */

//
// PyIntObject represents a (long) integer.  This is an immutable object;
// an integer cannot change its value after creation.
// 
// There are functions to create new integer objects, to test an object
// for integer-ness, and to get the integer value.  The latter functions
// returns -1 and sets errno to EBADF if the object is not an PyIntObject.
// None of the functions should be applied to nil objects.
// 
// The type PyIntObject is (unfortunately) exposed here so we can declare
// _Py_TrueStruct and _Py_ZeroStruct in boolobject.h; don't use this.

interface
  uses PythonTypes;
  
type 
  PyIntObject = record
    //PyObject_HEAD
  	ob_refcnt: 	Py_ssize_t;
  	ob_type: 	  PyTypeObjectPtr;

    ob_ival:    Long;
  end;

var PyInt_Type: PyTypeObject; cvar; external;

function PyInt_FromString(str: PChar; buf: PPChar; int: Integer): PyObjectPtr; cdecl; external;

//#ifdef Py_USING_UNICODE
//function PyInt_FromUnicode(Py_UNICODE*, Py_ssize_t, int): PyObjectPtr;
//#endif

function PyInt_FromLong(v: Long): PyObjectPtr; cdecl; external;
function PyInt_FromSize_t(v: size_t): PyObjectPtr; cdecl; external;
function PyInt_FromSsize_t(v: Py_ssize_t): PyObjectPtr; cdecl; external;
function PyInt_AsLong(o: PyObjectPtr): Long; cdecl; external;
function PyInt_AsSsize_t(o: PyObjectPtr): Py_ssize_t; cdecl; external;
function PyInt_AsUnsignedLongMask(o: PyObjectPtr): ULong; cdecl; external;

//#ifdef HAVE_LONG_LONG
//function unsigned PY_LONG_LONG) PyInt_AsUnsignedLongLongMask(PyObjectPtr );
//#endif

function PyInt_GetMax(): Long; cdecl; external;

// These aren't really part of the Int object, but they're handy; the protos
 // * are necessary for systems that need the magic of PyAPI_FUNC and that want
 // * to have stropmodule as a dynamically loaded module instead of building it
 // * into the main Python shared library/DLL.  Guido thinks I'm weird for
 // * building it this way.  :-)  [cjh]
 // */
function PyOS_strtoul(s: PChar; buf: PPChar; int: Integer): ULong; cdecl; external;
function PyOS_strtol(s: PChar; buf: PPChar; int: Integer): Long; cdecl; external;




//TODO: #define PyInt_Check(op) PyObject_TypeCheck(op, &PyInt_Type)
//TODO: #define PyInt_CheckExact(op) ((op)->ob_type == &PyInt_Type)

// Macro, trading safety for speed */
//TODO: #define PyInt_AS_LONG(op) (((PyIntObject *)(op))->ob_ival)

implementation

end.